package panel.home
{
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	import assists.HtmlText;
	import assists.Lang;
	import assists.URI;
	import assists.resource.ResourceLoader;
	
	import inerface.IHomePanel;
	
	import panel.home.fastBtn.FastBtnGroup;
	import panel.mainPanel.MainNewsBox;
	
	public class HomePanel extends Sprite implements IHomePanel
	{	
		private var _fastBtnGroup:FastBtnGroup;
		
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		
		private var _onClose:Function;
		
		private var newsBox:MainNewsBox;
		
		private var _onLocation:Function;
		private var _onViewPath:Function;
		private var _onShowMyPath:Function;
		private var _onShowGetMore:Function;
		private var _onShowWeather:Function;
		
		private var showDetail:Function;
		private var _onSuntime:Function;
		private var _onHelp:Function;
		
		public function HomePanel()
		{
			
		}
		
		public function set onClose(func:Function):void
		{
			_onClose = func;
		}
		
		public function get content():Sprite
		{
			return this;
		}
		
		public function init(stage:Stage,loader:ResourceLoader,lang:Lang,uri:URI = null):void
		{	
			_stage = stage;
			_loader = loader;
			_lang = lang;
			
			_fastBtnGroup = new FastBtnGroup(_stage);
			_fastBtnGroup.init(navigation,localWeather,quickHelp,myPath,more,_onSuntime);
			this.addChild(_fastBtnGroup);
			
			newsBox = new MainNewsBox(_stage,_stage.stageWidth * .9,_stage.stageHeight * .25);
			this.addChild(newsBox);
		}
		
		public function changeData(list:Array):void
		{
			newsBox.onShowDetail = showDetail;
			
			if(list.length == 0){
				newsBox.title = HtmlText.formatSizeColor("<b>正在获取新闻</b>",0xFFFFff,20);
			}else{
				newsBox.title = HtmlText.formatSizeColor("<b>新闻速递</b>",0xFFFFff,20);
			}
			
			newsBox.changeData(list);
			newsBox.x = (_stage.stageWidth - newsBox.width)/2;
			newsBox.y = _stage.stageHeight *.55;
		}
		
		private function myPath():void
		{
			if(_onShowMyPath is Function){
				_onShowMyPath();
			}
		}
		
		private function quickHelp():void
		{
			trace("help");
			_onHelp();
		}
		
		private function localWeather():void
		{
			trace("weather");	
			if(_onShowWeather is Function){
				_onShowWeather();
			}
		}
		
		private function navigation():void
		{
			trace("navigation");	
			_onLocation();
		}
		
		private function more():void
		{
			trace("more");	
			//			_onViewPath();
			
			if(_onShowGetMore is Function){
				_onShowGetMore();
			}
		}
		
		public function clear():void
		{
			this.removeChild(newsBox);
			newsBox.clear();
			newsBox = null;
			
			_fastBtnGroup.clear();
		}
		
		public function set onLocation(func:Function):void
		{
			_onLocation = func;
		}
		
		public function set onViewPath(func:Function):void
		{
			_onViewPath = func;
		}
		
		public function set onShowMyPath(func:Function):void
		{
			_onShowMyPath = func;
		}
		
		public function set onShowGetMore(func:Function):void
		{
			_onShowGetMore = func;
		}
		
		public function set onHelp(func:Function):void
		{
			_onHelp = func;
		}
		
		public function set onShowWeather(func:Function):void
		{
			_onShowWeather = func;
		}
		
		public function set onSuntime(func:Function):void
		{
			_onSuntime = func;
		}
		
		public function set onNewsShowDetail(func:Function):void
		{
			showDetail = func;
		}
	}
}